package com.ruoyi.web.controller.media;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.media.MediaUser;
import com.ruoyi.system.service.media.IMediaUserService;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 广电用户Controller
 */
@RestController
@RequestMapping("/media/user")
public class MediaUserController extends BaseController {
    @Autowired
    private IMediaUserService mediaUserService;

    /**
     * 查询广电用户列表
     */
    @GetMapping("/list")
    public TableDataInfo list(MediaUser mediaUser) {
        startPage();
        List<MediaUser> list = mediaUserService.selectMediaUserList(mediaUser);
        return getDataTable(list);
    }

    /**
     * 导出广电用户列表
     */
    @Log(title = "广电用户", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MediaUser mediaUser) {
        List<MediaUser> list = mediaUserService.selectMediaUserList(mediaUser);
        ExcelUtil<MediaUser> util = new ExcelUtil<MediaUser>(MediaUser.class);
        util.exportExcel(response, list, "广电用户数据");
    }

    /**
     * 获取广电用户详细信息
     */
    @GetMapping(value = "/{userId}")
    public AjaxResult getInfo(@PathVariable("userId") Long userId) {
        return AjaxResult.success(mediaUserService.selectMediaUserById(userId));
    }

    /**
     * 新增广电用户
     */
    @Log(title = "广电用户", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MediaUser mediaUser) {
        return toAjax(mediaUserService.insertMediaUser(mediaUser));
    }

    /**
     * 修改广电用户
     */
    @Log(title = "广电用户", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MediaUser mediaUser) {
        return toAjax(mediaUserService.updateMediaUser(mediaUser));
    }

    /**
     * 删除广电用户
     */
    @Log(title = "广电用户", businessType = BusinessType.DELETE)
    @DeleteMapping("/{userIds}")
    public AjaxResult remove(@PathVariable Long[] userIds) {
        return toAjax(mediaUserService.deleteMediaUserByIds(userIds));
    }
}